<template>
  <el-card>
    <div>
      <h4>联系平台</h4>
    </div>
    <div class="mt-20px">
      <el-form-item label="联系电话：">
        <el-input v-model="detail.phone" placeholder="请输入联系电话" clearable />
      </el-form-item>
    </div>
    <div>最近更新时间：{{ detail.updateTime ? formatDate(detail.updateTime as any) : '-' }}</div>
    <div class="mt-20px">
      <el-button type="primary" :loading="formLoading" @click="submitForm">保存</el-button>
    </div>
  </el-card>
</template>
<script setup lang="ts">
import { ContactPlatformApi, ContactPlatform } from '@/api/biz/contactplatform'
import { formatDate } from '@/utils/formatTime'

const { t } = useI18n() // 国际化
const message = useMessage()

const detail = ref<ContactPlatform>({
  id: 1,
  phone: '',
  updateTime: undefined
})
const formLoading = ref(false)

const submitForm = async () => {
  // 提交请求
  formLoading.value = true
  try {
    const data = detail.value as unknown as ContactPlatform
    await ContactPlatformApi.updateContactPlatform({
      ...data,
      updateTime: Date.now().toString()
    })
    message.success(t('common.updateSuccess'))
    ContactPlatformApi.getContactPlatform(1).then((data) => {
      detail.value = data
    })
  } finally {
    formLoading.value = false
  }
}

ContactPlatformApi.getContactPlatform(1).then((data) => {
  detail.value = data
})
</script>
